package com.example.zp;


import android.content.Context;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * A simple {@link Fragment} subclass.
 */
public class WechatFragment extends Fragment {

    private View view;

    private RecyclerView recyclerView;
    private List<String> list;
    private List<Integer> imgList;
    private Context context;
    private Adapter adapter;

    public WechatFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.tab_home, container, false);
        recyclerView = view.findViewById(R.id.recyclerView);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        context = (MainActivity)getActivity();

        initResource();

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

        adapter = new Adapter(context, list, imgList);

        ItemTouchHelper.Callback callback = new SwipeItemTouchHelper(adapter);
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
        itemTouchHelper.attachToRecyclerView(recyclerView);

        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(adapter);
    }

    // 初始化各种资源
    private void initResource() {
        list = new ArrayList<>();
        imgList = new ArrayList<>();

        Map<Integer, String> map = new HashMap<>();

        map.put(R.drawable.blg, "BLG哔哩哔哩电竞俱乐部");
        map.put(R.drawable.dmo, "DominusEsports");
        map.put(R.drawable.edg, "EdwardGaming");
        map.put(R.drawable.es, "eStarGaming");
        map.put(R.drawable.fpx, "FunPlusPhoenix");
        map.put(R.drawable.ig, "InvictusGaming");
        map.put(R.drawable.omg, "OHMYGOD");
        map.put(R.drawable.rng, "RoyalNeverGiveUp");
        map.put(R.drawable.we, "TeamWE");
        map.put(R.drawable.sn, "SUNING");
        map.put(R.drawable.lng, "LNGEsports");

        for (Integer key : map.keySet()) {
            list.add(map.get(key));
            imgList.add(key);
        }

    }

}
